<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class YARP::Pattern - yarp: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="../Object.html">Object</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-combine_and">#combine_and</a>
    <li ><a href="#method-i-combine_or">#combine_or</a>
    <li ><a href="#method-i-compile">#compile</a>
    <li ><a href="#method-i-compile_alternation_pattern_node">#compile_alternation_pattern_node</a>
    <li ><a href="#method-i-compile_array_pattern_node">#compile_array_pattern_node</a>
    <li ><a href="#method-i-compile_constant_path_node">#compile_constant_path_node</a>
    <li ><a href="#method-i-compile_constant_read_node">#compile_constant_read_node</a>
    <li ><a href="#method-i-compile_error">#compile_error</a>
    <li ><a href="#method-i-compile_hash_pattern_node">#compile_hash_pattern_node</a>
    <li ><a href="#method-i-compile_nil_node">#compile_nil_node</a>
    <li ><a href="#method-i-compile_node">#compile_node</a>
    <li ><a href="#method-i-compile_regular_expression_node">#compile_regular_expression_node</a>
    <li ><a href="#method-i-compile_string_node">#compile_string_node</a>
    <li ><a href="#method-i-compile_symbol_node">#compile_symbol_node</a>
    <li ><a href="#method-i-scan">#scan</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-YARP::Pattern">
    <h1 id="class-YARP::Pattern" class="class">
      class YARP::Pattern
    </h1>

    <section class="description">
    
<p>A pattern is an object that wraps a Ruby pattern matching expression. The expression would normally be passed to an ‘in` clause within a `case` expression or a rightward assignment expression. For example, in the following snippet:</p>

<pre class="ruby"><span class="ruby-keyword">case</span> <span class="ruby-identifier">node</span>
<span class="ruby-keyword">in</span> <span class="ruby-constant">ConstantPathNode</span>[<span class="ruby-constant">ConstantReadNode</span>[<span class="ruby-value">name:</span> <span class="ruby-value">:YARP</span>], <span class="ruby-constant">ConstantReadNode</span>[<span class="ruby-value">name:</span> <span class="ruby-value">:Pattern</span>]]
<span class="ruby-keyword">end</span>
</pre>

<p>the pattern is the ‘<a href="...">ConstantPathNode</a>` expression.</p>

<p>The pattern gets compiled into an object that responds to call by running the <a href="Pattern.html#method-i-compile"><code>compile</code></a> method. This method itself will run back through <a href="../YARP.html"><code>YARP</code></a> to parse the expression into a tree, then walk the tree to generate the necessary callable objects. For example, if you wanted to compile the expression above into a callable, you would:</p>

<pre class="ruby"><span class="ruby-identifier">callable</span> = <span class="ruby-constant">YARP</span><span class="ruby-operator">::</span><span class="ruby-constant">Pattern</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;ConstantPathNode[ConstantReadNode[name: :YARP], ConstantReadNode[name: :Pattern]]&quot;</span>).<span class="ruby-identifier">compile</span>
<span class="ruby-identifier">callable</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">node</span>)
</pre>

<p>The callable object returned by <a href="Pattern.html#method-i-compile"><code>compile</code></a> is guaranteed to respond to call with a single argument, which is the node to match against. It also is guaranteed to respond to ===, which means it itself can be used in a ‘case` expression, as in:</p>

<pre class="ruby"><span class="ruby-keyword">case</span> <span class="ruby-identifier">node</span>
<span class="ruby-keyword">when</span> <span class="ruby-identifier">callable</span>
<span class="ruby-keyword">end</span>
</pre>

<p>If the query given to the initializer cannot be compiled into a valid matcher (either because of a syntax error or because it is using syntax we do not yet support) then a <a href="Pattern/CompilationError.html"><code>YARP::Pattern::CompilationError</code></a> will be raised.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">



        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-query" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">query</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(query)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 58</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">query</span>)
  <span class="ruby-ivar">@query</span> = <span class="ruby-identifier">query</span>
  <span class="ruby-ivar">@compiled</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-compile" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="compile-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 63</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile</span>
  <span class="ruby-identifier">result</span> = <span class="ruby-constant">YARP</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-node">&quot;case nil\nin #{query}\nend&quot;</span>)
  <span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">result</span>.<span class="ruby-identifier">value</span>.<span class="ruby-identifier">statements</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">conditions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">pattern</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-scan" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">scan</span><span
                                class="method-args">(root) { |node| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="scan-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 68</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">scan</span>(<span class="ruby-identifier">root</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>, <span class="ruby-identifier">root</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>

  <span class="ruby-ivar">@compiled</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">compile</span>
  <span class="ruby-identifier">queue</span> = [<span class="ruby-identifier">root</span>]

  <span class="ruby-keyword">while</span> (<span class="ruby-identifier">node</span> = <span class="ruby-identifier">queue</span>.<span class="ruby-identifier">shift</span>)
    <span class="ruby-keyword">yield</span> <span class="ruby-identifier">node</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@compiled</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">node</span>)
    <span class="ruby-identifier">queue</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">node</span>.<span class="ruby-identifier">child_nodes</span>.<span class="ruby-identifier">compact</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-combine_and" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">combine_and</span><span
                                class="method-args">(left, right)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Shortcut for combining two procs into one that returns true if both return true.</p>

                              <div class="method-source-code" id="combine_and-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 84</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">combine_and</span>(<span class="ruby-identifier">left</span>, <span class="ruby-identifier">right</span>)
  <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">other</span>) { <span class="ruby-identifier">left</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">other</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">right</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">other</span>) }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-combine_or" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">combine_or</span><span
                                class="method-args">(left, right)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Shortcut for combining two procs into one that returns true if either returns true.</p>

                              <div class="method-source-code" id="combine_or-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 90</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">combine_or</span>(<span class="ruby-identifier">left</span>, <span class="ruby-identifier">right</span>)
  <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">other</span>) { <span class="ruby-identifier">left</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">other</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">right</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">other</span>) }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_alternation_pattern_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_alternation_pattern_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in foo | bar</p>

                              <div class="method-source-code" id="compile_alternation_pattern_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 125</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_alternation_pattern_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">combine_or</span>(<span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">node</span>.<span class="ruby-identifier">left</span>), <span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">node</span>.<span class="ruby-identifier">right</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_array_pattern_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_array_pattern_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in [foo, bar, baz]</p>

                              <div class="method-source-code" id="compile_array_pattern_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 100</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_array_pattern_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">compile_error</span>(<span class="ruby-identifier">node</span>) <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">node</span>.<span class="ruby-identifier">rest</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">posts</span>.<span class="ruby-identifier">any?</span>

  <span class="ruby-identifier">constant</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">constant</span>
  <span class="ruby-identifier">compiled_constant</span> = <span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">constant</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">constant</span>

  <span class="ruby-identifier">preprocessed</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">requireds</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">required</span><span class="ruby-operator">|</span> <span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">required</span>) }

  <span class="ruby-identifier">compiled_requireds</span> = <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">other</span>) <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">deconstructed</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">deconstruct</span>

    <span class="ruby-identifier">deconstructed</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">preprocessed</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&amp;&amp;</span>
      <span class="ruby-identifier">preprocessed</span>
        .<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">deconstructed</span>)
        .<span class="ruby-identifier">all?</span> { <span class="ruby-operator">|</span>(<span class="ruby-identifier">matcher</span>, <span class="ruby-identifier">value</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">matcher</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">value</span>) }
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">compiled_constant</span>
    <span class="ruby-identifier">combine_and</span>(<span class="ruby-identifier">compiled_constant</span>, <span class="ruby-identifier">compiled_requireds</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">compiled_requireds</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_constant_path_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_constant_path_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in <a href="ConstantReadNode.html"><code>YARP::ConstantReadNode</code></a></p>

                              <div class="method-source-code" id="compile_constant_path_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 130</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_constant_path_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">parent</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">parent</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ConstantReadNode</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">slice</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;YARP&quot;</span>
    <span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">node</span>.<span class="ruby-identifier">child</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">compile_error</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_constant_read_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_constant_read_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in <a href="ConstantReadNode.html"><code>ConstantReadNode</code></a> in String</p>

                              <div class="method-source-code" id="compile_constant_read_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 142</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_constant_read_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">value</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">slice</span>

  <span class="ruby-keyword">if</span> <span class="ruby-constant">YARP</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">value</span>, <span class="ruby-keyword">false</span>)
    <span class="ruby-identifier">clazz</span> = <span class="ruby-constant">YARP</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">value</span>)

    <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">other</span>) { <span class="ruby-identifier">clazz</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span> }
  <span class="ruby-keyword">elsif</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">value</span>, <span class="ruby-keyword">false</span>)
    <span class="ruby-identifier">clazz</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">value</span>)

    <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">other</span>) { <span class="ruby-identifier">clazz</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span> }
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">compile_error</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_error" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_error</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Raise an error because the given node is not supported.</p>

                              <div class="method-source-code" id="compile_error-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 95</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_error</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">CompilationError</span>, <span class="ruby-identifier">node</span>.<span class="ruby-identifier">inspect</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_hash_pattern_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_hash_pattern_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in InstanceVariableReadNode[name: Symbol] in { name: Symbol }</p>

                              <div class="method-source-code" id="compile_hash_pattern_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 160</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_hash_pattern_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">compile_error</span>(<span class="ruby-identifier">node</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">kwrest</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-identifier">compiled_constant</span> = <span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">node</span>.<span class="ruby-identifier">constant</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">constant</span>

  <span class="ruby-identifier">preprocessed</span> =
    <span class="ruby-identifier">node</span>.<span class="ruby-identifier">assocs</span>.<span class="ruby-identifier">to_h</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">assoc</span><span class="ruby-operator">|</span>
      [<span class="ruby-identifier">assoc</span>.<span class="ruby-identifier">key</span>.<span class="ruby-identifier">unescaped</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">compile_node</span>(<span class="ruby-identifier">assoc</span>.<span class="ruby-identifier">value</span>)]
    <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">compiled_keywords</span> = <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">other</span>) <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">deconstructed</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">deconstruct_keys</span>(<span class="ruby-identifier">preprocessed</span>.<span class="ruby-identifier">keys</span>)

    <span class="ruby-identifier">preprocessed</span>.<span class="ruby-identifier">all?</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">keyword</span>, <span class="ruby-identifier">matcher</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">deconstructed</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">keyword</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">matcher</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">deconstructed</span>[<span class="ruby-identifier">keyword</span>])
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">compiled_constant</span>
    <span class="ruby-identifier">combine_and</span>(<span class="ruby-identifier">compiled_constant</span>, <span class="ruby-identifier">compiled_keywords</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">compiled_keywords</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_nil_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_nil_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in nil</p>

                              <div class="method-source-code" id="compile_nil_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 185</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_nil_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">attribute</span>) { <span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">nil?</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Compile any kind of node. Dispatch out to the individual compilation methods based on the type of node.</p>

                              <div class="method-source-code" id="compile_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 214</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">node</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">AlternationPatternNode</span>
    <span class="ruby-identifier">compile_alternation_pattern_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">ArrayPatternNode</span>
    <span class="ruby-identifier">compile_array_pattern_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">ConstantPathNode</span>
    <span class="ruby-identifier">compile_constant_path_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">ConstantReadNode</span>
    <span class="ruby-identifier">compile_constant_read_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">HashPatternNode</span>
    <span class="ruby-identifier">compile_hash_pattern_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">NilNode</span>
    <span class="ruby-identifier">compile_nil_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">RegularExpressionNode</span>
    <span class="ruby-identifier">compile_regular_expression_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">StringNode</span>
    <span class="ruby-identifier">compile_string_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">SymbolNode</span>
    <span class="ruby-identifier">compile_symbol_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">compile_error</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_regular_expression_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_regular_expression_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in /foo/</p>

                              <div class="method-source-code" id="compile_regular_expression_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 190</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_regular_expression_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">node</span>.<span class="ruby-identifier">unescaped</span>, <span class="ruby-identifier">node</span>.<span class="ruby-identifier">closing</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span>])

  <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">attribute</span>) { <span class="ruby-identifier">regexp</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">attribute</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_string_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_string_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in “” in “foo”</p>

                              <div class="method-source-code" id="compile_string_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 198</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_string_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">string</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">unescaped</span>

  <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">attribute</span>) { <span class="ruby-identifier">string</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">attribute</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-compile_symbol_node" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_symbol_node</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>in :+ in :foo</p>

                              <div class="method-source-code" id="compile_symbol_node-source">
            <pre><span class="ruby-comment"># File yarp/pattern.rb, line 206</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compile_symbol_node</span>(<span class="ruby-identifier">node</span>)
  <span class="ruby-identifier">symbol</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">unescaped</span>.<span class="ruby-identifier">to_sym</span>

  <span class="ruby-operator">-&gt;</span>(<span class="ruby-identifier">attribute</span>) { <span class="ruby-identifier">symbol</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">attribute</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

